using System;
using System.Net;
using Lidgren.Library.Network;

namespace SharpWind.Network
{
	public class Connection
	{
		private IPEndPoint endPoint = null;

		private NetConnection connection = null;

		private string playerName = string.Empty;

		public Connection( NetConnection connection )
		{
			this.connection = connection;
			this.endPoint	= this.connection.RemoteEndpoint;
		}

		public Connection( string playerName, IPEndPoint endPoint )
		{
			this.playerName = playerName;
			this.endPoint	= endPoint;
		}

		public void Disconnect()
		{
			Disconnect( Reason.None );
		}

		public void Disconnect( string reason )
		{
			this.connection.Disconnect( reason );
		}

		public void SetConnection( NetConnection connection )
		{
			this.connection = connection;
		}

		public string PlayerName
		{
			get
			{
				return this.playerName;
			}
		}

		public IPEndPoint EndPoint
		{
			get
			{
				return this.endPoint;
			}
		}

		public NetStatistics Statistics
		{
			get
			{
				return this.connection.Statistics;
			}
		}

		public float AverageRoundtripTime
		{
			get
			{
				return this.connection.AverageRoundtripTime * 1000f;
			}
		}

		public static implicit operator NetConnection( Connection connection )
		{
			return connection.connection;
		}
	}
}
